package com.xnyzc.lhy.mis.controller.cmsapi.role;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.mis.entity.param.cms.RoleReceive;
import com.xnyzc.lhy.mis.service.cms.role.RoleService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 系统配置
 * @Author conglijuan
 * @Date 2019/8/2 16:31
 **/
@RestController
@RequestMapping(value = "/cms/rewrite/role")
public class RoleControllerRewrite {

    @Autowired
    private RoleService roleService;


    /**
     * 新增、修改角色
     *
     * @return
     */
    @ApiOperation(value = "新增、修改角色", notes = "新增、修改角色")
    @GetMapping(value = "/getUpdateRole")
    public Rv getUpdateRole(
            Long roleId,String dataScope,String enname,String isSys,String name,Long officeId,String roleType,String useable,String selectMenuList
    ) {
        String[] selectMenuLists = selectMenuList.split(";");
        long [] strArrNum =(long[]) ConvertUtils.convert(selectMenuLists,long.class);
        List<Long> menuList = new ArrayList<>();
        for (int i = 0; i <strArrNum.length ; i++) {
            menuList.add(strArrNum[i]);
        }
        return Rv.wrap(roleService.getUpdateRole(roleId,dataScope,enname,isSys,name,officeId,roleType,useable,menuList));
    }


    /**
     * 角色分配
     *
     * @return
     */
    @ApiOperation(value = "角色分配", notes = "角色分配")
    @GetMapping(value = "/getRoleAllocation")
    public Rv getRoleAllocation(
            Long roleId,String userIdList
    ) {
        String[] userIdArray =userIdList.split(";");
        long [] strArrNum =(long[]) ConvertUtils.convert(userIdArray,long.class);
        List<Long> userList = new ArrayList<>();
        for (int i = 0; i <strArrNum.length ; i++) {
            userList.add(strArrNum[i]);
        }
        return Rv.wrap(roleService.getRoleAllocation(roleId,userList));
    }

}
